package com.vca.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.vca.common.result.CommonResult;
import com.vca.service.service.InvoiceRecordService;
import com.vca.service.service.ObsService;
import com.vca.service.service.UmsPayService;
import com.vca.service.service.VhallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Li
 * @program VCA_Mini_Program
 * @description 回调控制器
 * @classname OpenController
 * @since 2022/12/29 14:09:46
 **/

@Slf4j
@RestController("OpenController")
@RequestMapping("api/admin/open")
@Api(tags = "回调控制器")
public class OpenController {

    @Autowired
    private UmsPayService umsPayService;

    @Autowired
    private VhallService vhallService;

    @Autowired
    private InvoiceRecordService invoiceRecordService;

    /**
     * @Description: 银联商务 全民付 支付结果通知
     * @Author: Li
     * @Date: 2022/10/31 09:45
     */
    @ApiOperation(value = "银联商务 全民付 支付结果通知")
    @PostMapping("/ums/resultInform")
    public CommonResult<String> resultInform(@RequestParam Map<String, Object> params) throws Exception {
        return umsPayService.resultInform(params) ? CommonResult.success("SUCCESS") : CommonResult.failed("FAILED");
    }

    /**
     * @param params
     * @return java.lang.String
     * @description k值校验
     * @methodName check
     * @author Li
     * @date 2022/12/29 11:06
     */
    @ApiOperation(value = "k值校验")
    @PostMapping(value = "/vhall/check")
    public String check(@RequestParam Map<String, Object> params) {
        return vhallService.check(params);
    }

    /**
     * @param json
     * @return com.vca.common.result.CommonResult
     * @description 微吼直播状态回调
     * @author Li
     * @date 2022/12/27 15:32
     */
    @ApiOperation("微吼直播状态回调")
    @PostMapping("/vhall/callback")
    public CommonResult callBack(@RequestBody String json) {
        return vhallService.callBack(json) ? CommonResult.success() : CommonResult.failed();
    }


    /**
     * @param json
     * @return {@link String}
     * @description 结算单反馈，销项发票协同接口(发票回调)
     * @author Li
     * @date 2023/2/13 13:09
     */
    @ApiOperation("结算单反馈，销项发票协同接口(发票回调)")
    @PostMapping("/invoiceResultDownload")
    public JSONObject invoiceResultDownload(@RequestBody String json) {
        return invoiceRecordService.invoiceResultDownload(json);
    }

    @Resource
    private ObsService obsService;

    @ApiOperation("同步数据到OBS")
    @GetMapping(value = "/sync/obs")
    public CommonResult<String> syncObs() {
        obsService.sync();
        return CommonResult.success();
    }

}
